package com.medicine.hbp.adapter;

import java.util.List;

import org.kymjs.kjframe.http.HttpParams;

import com.medicine.hbp.http.AppHttpCallBack;
import com.medicine.hbp.http.AppHttps;
import com.medicine.hbp.http.HttpInterface;
import com.medicine.hbp.mob.OptionListVo;
import com.medicine.hbp.mob.artGroupListVo;
import com.medicine.hbp.mob.artLaberVo;
import com.medicine.hbp.ui.SearchActivity;
import com.medicine.hbp.uitl.ToastUtil;
import com.medicine.hbp.R;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
/**
 * @author Administrator
 *
 */
public class BtqianAdapter extends BaseAdapter {
	/**
	 */
	public List<artLaberVo> artLaber;
	private LayoutInflater inflater;
	private Activity activity;
	/**
	 */
	private int type;
	public BtqianAdapter(Activity activity, List<artLaberVo> artLaber) {
		this.artLaber = artLaber;
		this.activity = activity;
		inflater = LayoutInflater.from(activity);
	}
	public List<artLaberVo> getLaberVos() {
			return artLaber;
	}
	@Override
	public int getCount() {
		return artLaber.size();
	}

	@Override
	public Object getItem(int arg0) {
		return arg0;
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(final int arg0, View view, ViewGroup arg2) {
		ViewHolder holder;
		if (view == null) {
			holder = new ViewHolder();
			view = inflater.inflate(R.layout.item_bq, null);
			holder.text = (Button) view.findViewById(R.id.button2);
			view.setTag(holder);
		} else {
			holder = (ViewHolder) view.getTag();
		}
		final artLaberVo listVo = artLaber.get(arg0);
		if (listVo != null) {
			holder.text.setText(listVo.laberName);
			holder.text.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View arg0) {
					httpSearchLaber(listVo.laberName);
				}
			});
			view.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View arg0) {
					httpSearchLaber(listVo.laberName);
				}
			});
		}
		
		return view;
	}

	class ViewHolder {
		Button text;
	}
	
	/**
	 * ����
	 */
	private void httpSearchLaber(String context) {
		HttpParams params = new HttpParams();
		params.put("keyword", context);//�û�������Ҫ����������
		AppHttps.HttpPost(activity,HttpInterface.SEARCH_LABER, params,
				new AppHttpCallBack<artGroupListVo>(artGroupListVo.class,activity) {
					@Override
					public void onSuccess(artGroupListVo result) {
						Intent intent=new Intent(activity,SearchActivity.class);
						intent.putExtra("result", result);
						activity.startActivity(intent);
					}

					@Override
					public void onFailures(int errorCode, String errorMsg) {
						ToastUtil.showShort(activity, errorMsg);
					}
				});

	}

}
